package com.knowif.service;

import com.knowif.dao.TUserMapper;
import com.knowif.dao.UserOrderMapper;
import com.knowif.pojo.UserOrder;
import com.knowif.system.model.RestBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserOrderSelectService {
    @Autowired
    private UserOrderMapper userOrderMapper;
    @Autowired
    private TUserMapper tUserMapper;

    /**
     * 列出当前用户对应的所有订单，分页
     * */
   public RestBean<?> selectOrderByUserId(int userId, int page, int amount){
       if(page < 2){
           page = 0;
       }else{
           page--;
       }
       page = page * amount;
       List<UserOrder> userOrders = userOrderMapper.selectByUserId(userId,page,amount);
       return RestBean.buildSuccess(userOrders);
   }
    /**
     *  查询id对应的订单
     * */
    public RestBean<?> selectUserOrderById(int id){
       return RestBean.buildSuccess(userOrderMapper.selectByPrimaryKey(id));
    }


    /**
     * 查询订单 以及包含导师信息
     * */
    public RestBean<?> selectOrderStepById(int userOrderId){
        return RestBean.buildSuccess(userOrderMapper.selectOrderStepById(userOrderId));
    }
    /**
     * 查询用户信息By Id
     * **/
    public RestBean<?> selectUserById(int userId){
        return RestBean.buildSuccess(tUserMapper.selectByPrimaryKey(userId).getAvatarUrl());
    }

}
